package com.ingesup.dao;

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.List;

import org.junit.Before;
import org.junit.Test;

import com.ingesup.entities.Contact;
import com.ingesup.entities.ListeDeDiffusion;

public class ListeDeDiffusionDaoTest {

	private static ListeDeDiffusionDao dao;
	private static ListeDeDiffusion liste;
	
	@Before
	public void beforeTest() {
		dao = new ListeDeDiffusionDaoImpl(ListeDeDiffusion.class);		
	}
	
	
	@Test
	public void testCreate() {
		ListeDeDiffusion temp = new ListeDeDiffusion();
		List<Contact> liste = new ArrayList<Contact>();
		Contact contact = new Contact();
		contact.setNom("DEJEAN");
		contact.setAdresseMail("florian.dejean@gmail.com");
		liste.add(contact);
		temp.setNom("maListe");
		temp.setListeDeContacts(liste);
		
		ListeDeDiffusion temp2 = dao.create(temp);
		assertNotNull(temp2);
		assertTrue(temp2.getId() > 0);
	}


	@Test
	public void testReadAll() {
		List<ListeDeDiffusion> tempList = new ArrayList<ListeDeDiffusion>();
		tempList = dao.getAll();
		assertEquals(1, tempList.size());
		liste = tempList.get(0);
	}
	
	
	@Test
	public void testRead() {
		ListeDeDiffusion temp = dao.read(liste.getId());
		assertNotNull(temp);
		assertNotNull(temp.getNom());
		assertNotNull(temp.getListeDeContacts());
	}


	@Test
	public void testUpdate() {
		ListeDeDiffusion temp = dao.read(liste.getId());
		temp.setNom("Nounouille");
		dao.update(temp);
		
		temp = dao.read(liste.getId());
		assertEquals("Nounouille", temp.getNom());
	}


	@Test
	public void testDelete() {
		dao.delete(liste);
		assertEquals(0, dao.getAll().size());
	}
}
